package com.wn.trade.controller;

import com.wn.common.model.borrow.BorrowRecordDTO;
import com.wn.common.model.borrow.BorrowRecordQuery;
import com.wn.common.model.borrow.BorrowRecordVo;
import com.wn.common.result.Result;
import com.wn.common.utils.Pages;
import com.wn.trade.service.IBorrowRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Docter
 * @date 2023 -07-31
 * @desc
 */
@RestController
public class TradeController {

    @Autowired
    private IBorrowRecordService borrowRecordService;

    @ApiOperation("借款申请...")
    @PostMapping("/trade/borrow")
    public String borrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO) {
        //进行 借款
        borrowRecordService.borrow(borrowRecordDTO);
        return "借款成功...";
    }

    /**
     *
     * @param pageNum
     * @param pageSize
     * @param borrowRecordQuery
     * @return
     * @RequestParam  获取请求参数   设置默认值 defaultValue = "1"
     *
     */
    @ApiOperation("借款记录查询")
    @PostMapping("/trade/borrow/query")
    public Result<Pages<BorrowRecordVo>> queryBorrowRecord(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "2") Integer pageSize,
            @RequestBody BorrowRecordQuery borrowRecordQuery) {
        Pages<BorrowRecordVo> pages =
                borrowRecordService.queryBorrowRecord(pageNum,pageSize,borrowRecordQuery);
        return Result.ok(pages);
    }

    @ApiOperation("借款审核")
    @PutMapping("/trade/borrow/status")
    public Result changeBorrowRecordStatus(
            @RequestParam Integer approveStatus,
            @RequestParam Long borrowRecordId) {

        String result =  borrowRecordService.changeBorrowRecordStatus(approveStatus,borrowRecordId);

        return Result.ok(result);
    }

}
